blob: e25a65a80fafb7143957247e2fd85d64a701ddf5 [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231git-update-ref(1)
2=================
3
4NAME
5----
Junio C Hamano7c73c662007-01-19 00:37:506git-update-ref - Update the object name stored in a ref safely
Junio C Hamano1a4e8412005-12-27 08:17:237
8SYNOPSIS
9--------
Junio C Hamanofce7c7e2008-07-02 03:06:3810'git update-ref' [-m <reason>] (-d <ref> [<oldvalue>] | [--no-deref] <ref> <newvalue> [<oldvalue>])
Junio C Hamano1a4e8412005-12-27 08:17:2311
12DESCRIPTION
13-----------
14Given two arguments, stores the <newvalue> in the <ref>, possibly
Junio C Hamanofce7c7e2008-07-02 03:06:3815dereferencing the symbolic refs. E.g. `git update-ref HEAD
Junio C Hamano1a4e8412005-12-27 08:17:2316<newvalue>` updates the current branch head to the new object.
17
18Given three arguments, stores the <newvalue> in the <ref>,
19possibly dereferencing the symbolic refs, after verifying that
20the current value of the <ref> matches <oldvalue>.
Junio C Hamanofce7c7e2008-07-02 03:06:3821E.g. `git update-ref refs/heads/master <newvalue> <oldvalue>`
Junio C Hamano1a4e8412005-12-27 08:17:2322updates the master branch head to <newvalue> only if its current
Junio C Hamanoa2ec14f2006-11-02 00:22:4823value is <oldvalue>. You can specify 40 "0" or an empty string
24as <oldvalue> to make sure that the ref you are creating does
25not exist.
Junio C Hamano1a4e8412005-12-27 08:17:2326
27It also allows a "ref" file to be a symbolic pointer to another
28ref file by starting with the four-byte header sequence of
29"ref:".
30
31More importantly, it allows the update of a ref file to follow
32these symbolic pointers, whether they are symlinks or these
33"regular file symbolic refs". It follows *real* symlinks only
34if they start with "refs/": otherwise it will just try to read
35them and update them as a regular file (i.e. it will allow the
36filesystem to follow them, but will overwrite such a symlink to
37somewhere else with a regular filename).
38
Junio C Hamanof2ce2972007-05-20 19:12:0939If --no-deref is given, <ref> itself is overwritten, rather than
40the result of following the symbolic pointers.
41
Junio C Hamano1a4e8412005-12-27 08:17:2342In general, using
43
Junio C Hamanofce7c7e2008-07-02 03:06:3844git update-ref HEAD "$head"
Junio C Hamano1a4e8412005-12-27 08:17:2345
46should be a _lot_ safer than doing
47
48echo "$head" > "$GIT_DIR/HEAD"
49
50both from a symlink following standpoint *and* an error checking
51standpoint. The "refs/" rule for symlinks means that symlinks
52that point to "outside" the tree are safe: they'll be followed
53for reading but not for writing (so we'll never write through a
54ref symlink to some other tree, if you have copied a whole
55archive by creating a symlink tree).
56
Junio C Hamanoa2ec14f2006-11-02 00:22:4857With `-d` flag, it deletes the named <ref> after verifying it
58still contains <oldvalue>.
59
60
Junio C Hamano341071d2006-06-04 07:24:4861Logging Updates
62---------------
63If config parameter "core.logAllRefUpdates" is true or the file
Junio C Hamanofce7c7e2008-07-02 03:06:3864"$GIT_DIR/logs/<ref>" exists then `git update-ref` will append
Junio C Hamano341071d2006-06-04 07:24:4865a line to the log file "$GIT_DIR/logs/<ref>" (dereferencing all
66symbolic refs before creating the log name) describing the change
67in ref value. Log lines are formatted as:
68
69 . oldsha1 SP newsha1 SP committer LF
70+
71Where "oldsha1" is the 40 character hexadecimal value previously
72stored in <ref>, "newsha1" is the 40 character hexadecimal value of
73<newvalue> and "committer" is the committer's name, email address
74and date in the standard GIT committer ident format.
75
76Optionally with -m:
77
78 . oldsha1 SP newsha1 SP committer TAB message LF
79+
80Where all fields are as described above and "message" is the
81value supplied to the -m option.
82
83An update will fail (without changing <ref>) if the current user is
84unable to create a new log file, append to the existing log file
85or does not have committer information available.
86
Junio C Hamano1a4e8412005-12-27 08:17:2387GIT
88---
Junio C Hamanof7c042d2008-06-06 22:50:5389Part of the linkgit:git[1] suite